package com.dysoft.flesh.ui;

import com.dysoft.bones.Event;
import com.dysoft.bones.InputEvent;
import com.dysoft.bones.Property;
import com.dysoft.bones.StateMachine;
import com.dysoft.flesh.RenderContext;
import com.dysoft.flesh.Renderer;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Sean Micklethwaite
 *         Oct 18, 2010 10:27:09 PM
 */
public abstract class UiComponent extends StateMachine<UiComponent.State> {
	protected UiComponent() {
		super(new NullState());
	}
	protected UiComponent(State state) {
		super(state);
	}


	/**
	 * Controls how the component reacts to events.
	 */
	public interface State extends StateMachine.State {
		Event.Status onKeyDown(Event.Status es, InputEvent.Key key);
		Event.Status onKeyUp(Event.Status es, InputEvent.Key key);
		Event.Status onMouseDown(Event.Status es, int x, int y, int button);
		Event.Status onMouseUp(Event.Status es, int x, int y, int button);
		Event.Status onMouseOver(Event.Status es, int x, int y);
		Event.Status onMouseOut(Event.Status es);
		Event.Status onScroll(Event.Status es, int x, int y, float amtx, float amty, float amtz);
	}

	public class BaseState extends StateMachine<State>.BaseState implements State {
		public BaseState(State parent) {
			super(parent);
		}

		public Event.Status onKeyDown(Event.Status es, InputEvent.Key key) {
			return getParent().onKeyDown(es, key);
		}

		public Event.Status onKeyUp(Event.Status es, InputEvent.Key key) {
			return getParent().onKeyUp(es, key);
		}

		public Event.Status onMouseDown(Event.Status es, int x, int y, int button) {
			return getParent().onMouseDown(es, x, y, button);
		}

		public Event.Status onMouseUp(Event.Status es, int x, int y, int button) {
			return getParent().onMouseUp(es, x, y, button);
		}

		public Event.Status onMouseOver(Event.Status es, int x, int y) {
			return getParent().onMouseOver(es, x, y);
		}

		public Event.Status onMouseOut(Event.Status es) {
			return getParent().onMouseOut(es);
		}

		public Event.Status onScroll(Event.Status es, int x, int y, float amtx, float amty, float amtz) {
			return getParent().onScroll(es, x, y, amtx, amty, amtz);
		}

		public UiComponent getUiComponent() {
			return UiComponent.this;
		}
	}
	public static class NullState extends StateMachine.NullState implements State {
		public Event.Status onKeyDown(Event.Status es, InputEvent.Key key) {
			return es;
		}

		public Event.Status onKeyUp(Event.Status es, InputEvent.Key key) {
			return es;
		}

		public Event.Status onMouseDown(Event.Status es, int x, int y, int button) {
			return es;
		}

		public Event.Status onMouseUp(Event.Status es, int x, int y, int button) {
			return es;
		}

		public Event.Status onMouseOver(Event.Status es, int x, int y) {
			return es;
		}

		public Event.Status onMouseOut(Event.Status es) {
			return es;
		}

		public Event.Status onScroll(Event.Status es, int x, int y, float amtx, float amty, float amtz) {
			return es;
		}
	}
}
